#ifndef __COMMANDS__
#define __COMMANDS__

#include "STM32f10x.h"
#include "stm32f10x_gpio.h"

#define INFO		  "\n<I>"
#define WARNING		  "\n<W>"
#define ERROR		  "\n<E>"
#define ANSWER		  "\n<A>"

#define BOARD_ID          "STM32VLD\n"

#define CMD_GET_ID        'i'
#define CMD_SET_SPEED     's'
#define CMD_GET_SPEED     'g'
#define CMD_STOP          'S'
#define CMD_GET_POS       'p'
#define CMD_GET_ADC       'a'

#define CMD_FORWARD       'f'
#define CMD_BACK          'b'
#define CMD_RIGHT         'r'
#define CMD_LEFT          'l'

#define CMD_CW            'z'
#define CMD_CCW           'x'
#define CMD_SET_STEPS     'm'

#define MAX_SPEED         1000

#define IS_VALID_ADC_CHANNEL(channel) (channel < 16)
#define IS_VALID_CHANNEL(channel) (channel >= 1 && channel <= 4)
#define IS_VALID_SPEED(speed)     (speed >= (-1)*(MAX_SPEED) && speed <= (MAX_SPEED))

/* Pins and PWMs assignment for motors */

#define M1_PWM_REGISTER   (TIM3->CCR1)
#define M1_PWM_PORT       GPIOC
#define M1_PWM_PIN        GPIO_Pin_6
#define M1_DIR1_PORT      GPIOC
#define M1_DIR1_PIN       GPIO_Pin_12
#define M1_DIR2_PORT      GPIOA
#define M1_DIR2_PIN       GPIO_Pin_14

#define M2_PWM_REGISTER   (TIM3->CCR3)
#define M2_PWM_PORT       GPIOC
#define M2_PWM_PIN        GPIO_Pin_8
#define M2_DIR1_PORT      GPIOC
#define M2_DIR1_PIN       GPIO_Pin_10
#define M2_DIR2_PORT      GPIOA
#define M2_DIR2_PIN       GPIO_Pin_12

#define M3_PWM_REGISTER   (TIM3->CCR2)
#define M3_PWM_PORT       GPIOC
#define M3_PWM_PIN        GPIO_Pin_7
#define M3_DIR1_PORT      GPIOC
#define M3_DIR1_PIN       GPIO_Pin_11
#define M3_DIR2_PORT      GPIOA
#define M3_DIR2_PIN       GPIO_Pin_13

#define M4_PWM_REGISTER   (TIM3->CCR4)
#define M4_PWM_PORT       GPIOC
#define M4_PWM_PIN        GPIO_Pin_9
#define M4_DIR1_PORT      GPIOA
#define M4_DIR1_PIN       GPIO_Pin_15
#define M4_DIR2_PORT      GPIOA
#define M4_DIR2_PIN       GPIO_Pin_11

/* Read ADC1 channel */
u16 readADC1(u8 channel);
/* Enable motor */
void EnableMotor(u8 channel);
/* Stop motor */
void StopMotor(u8 channel);
/* Set speed of specified motor */
int SetSpeed(u8 channel, int speed);
/* Get speed of specified motor */
int GetSpeed(u8 channel);

/* Process command from host */
void CMD_Process(char *cmd);

#endif

